import re
from rules import rules
def defaultErrorHandler(lineno,error):
    print("[line {}]{}".format(lineno,error))
def translate(code:str="",errorHandler=defaultErrorHandler):
    lineno=0
    res=""
    for line in code.splitlines():
        lineno+=1
        sline=line.strip()
        spaces=0
        for i in line:
            if(i==" "):
                spaces+=1
            else:break
        rule=None
        for i in rules:
            if(re.match(i[0],sline)):
                rule=i
                break
        if(not rule):
            errorHandler(lineno,"TransError: No rules found")
        stars=re.match(rule[0],sline).groups()
        trans=rule[1]
        for i in range(len(stars)):
            trans=trans.replace(f"${i+1}$",stars[i])
        # print(trans," ",stars,rule)
        res+=" "*spaces+trans+"\n"
    return res
def run(*args,**kwargs):
    exec(translate(*args,**kwargs))
run("""@0Oo a=int(input("oOo give me a number: "))
O0oo("get:",a)
0O(a>10):
    O0oo(a,"is bigger than ten")
0Oo(a<10):
    O0oo(a,"is smaller than ten")
0OO:
    O0oo(a,"equals ten")
oooo()""")